package br.com.ds3.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;

@Entity(name = "VOUCHER")
@SequenceGenerator(sequenceName = "SEQVOUCHER", name = "SEQVOUCHER", allocationSize=1, initialValue = 1)
public class Voucher extends GenericModel {

	@Id
	@Column(name = "IDVOUCHER")
	@GeneratedValue(generator = "SEQVOUCHER", strategy = GenerationType.SEQUENCE)	
	private Long id;
	
	@Column(name = "NOME", length = 50)
	private String nome;
	
	@Column(name = "VALOR")
	private Double valor; //Quantia ?
	
	@Column(name = "DESCONTO")
	private Double desconto; // Percentual ?

	@ManyToOne
	@JoinColumn(name = "IDUSUARIO")
	private Usuario usuario;	
	
	@ManyToMany( targetEntity=Pagamento.class,
			 cascade={CascadeType.PERSIST, CascadeType.MERGE} )
	@JoinTable( name="VOUCHER_PAGAMENTO",  
				joinColumns=@JoinColumn(name="IDVOUCHER"),  
				inverseJoinColumns=@JoinColumn(name="IDPAGAMENTO") )  		
	private List<Pagamento> pagamentos;
	
	@Override
	public Long getId() {
		return this.id;
	}

	@Override
	public void setId(Long id) {
		this.id = id;
	}

	public Usuario getUsuario() {
		return usuario;
	}

	public void setUsuario(Usuario usuario) {
		this.usuario = usuario;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public Double getValor() {
		return valor;
	}

	public void setValor(Double valor) {
		this.valor = valor;
	}

	public Double getDesconto() {
		return desconto;
	}

	public void setDesconto(Double desconto) {
		this.desconto = desconto;
	}

	public List<Pagamento> getPagamentos() {
		return pagamentos;
	}

	public void setPagamentos(List<Pagamento> pagamentos) {
		this.pagamentos = pagamentos;
	}
	
}
